package cn.study.luckyapp.assembler;
import cn.study.luckyclient.dto.UserUpdateCmd;
import cn.study.luckydomain.User.UserName;

import java.time.LocalDateTime;
import java.util.Date;
import cn.study.luckydomain.User.Password;

import cn.study.luckyclient.dto.UserRegisterCmd;
import cn.study.luckyclient.dto.data.UserVo;
import cn.study.luckydomain.User.UserEntity;

public class UserAssembler{
    public static UserEntity toAddEntity(UserRegisterCmd cmd) {
        UserEntity userEntity = new UserEntity();
        userEntity.setUsername(new UserName(cmd.getUserName()));
        userEntity.setPassword(new Password(cmd.getPassword()));
        userEntity.setName(cmd.getName());
        userEntity.setPhone(cmd.getPhone());
        userEntity.setCreateTime(LocalDateTime.now());
        userEntity.setUpdateTime(LocalDateTime.now());
        return userEntity;
    }

    public static UserVo toUserVo(UserEntity userEntity) {
        UserVo userVo = new UserVo();
        userVo.setId(userEntity.getId());
        userVo.setUsername(userEntity.getUsername().getUserName());
        userVo.setName(userEntity.getName());
        userVo.setPhone(userEntity.getPhone());
        userVo.setCreateTime(userEntity.getCreateTime());
        userVo.setUpdateTime(userEntity.getUpdateTime());
        return userVo;
    }
    public static UserEntity toAddEntity(UserUpdateCmd cmd) {
        UserEntity userEntity = new UserEntity();
        userEntity.setUsername(new UserName(cmd.getUserName()));
        userEntity.setPassword(new Password(cmd.getPassword()));
        userEntity.setName(cmd.getName());
        userEntity.setPhone(cmd.getPhone());
        userEntity.setUpdateTime(LocalDateTime.now());
        return userEntity;
    }
}
